/*
 *	dfregex_list.c
 *	© 2009 DigiFi Limited
 *
 *	Container for function that generates regex strings (big function)
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "../headers/dfregex.h"
#include "../headers/dfclient.h"
#include "util/stringconcat.h"

// definitions for the command patterns
#define DFREGEX_GENERALRESPONSE "\\[(.+)\\]"
#define DFREGEX_GENERALERROR "\\[ERR (.+)\\]"

#define DFREGEX_ANYTHING "([^]]+)"

#define DFREGEX_STRINGOPTIONAL "\"([^\"]*)\""			// Took out the not new line/return
#define DFREGEX_STRINGREQUIRED "\"([^\"]+)\""
#define DFREGEX_STRINGMULTILINE "\"([^\"]+)\""
#define DFREGEX_STRINGMULTILINEOPTIONAL "\"([^\"]*)\""
#define DFREGEX_STRINGEXTENSION "\"([^\"\\r\\n]{{0,3}})\""
#define DFREGEX_STRINGUNQUOTED "([^[:space:]]+)"
		

#define DFREGEX_NUMBERQUOTEDOPTIONAL "\"([0-9]*)\""		// TODO allow for -ve numbers
#define DFREGEX_NUMBERQUOTEDREQUIRED "\"([0-9]+)\""		// TODO fix for -ve numbers
#define DFREGEX_NUMBERUNQUOTED "([0-9]+)"	// TODO fix for -ve numbers


#define DFREGEX_DATE "\"([0-9]+-[0-9]+-[0-9]+)\""
#define DFREGEX_TIME "\"([0-9]+:[0-9]+:[0-9]+)\""
#define DFREGEX_BOOLEAN "\"([0-1])\""
#define DFREGEX_IPADDRESS "\"(([0-9]{{1,3}}\\.[0-9]{{1,3}}\\.[0-9]{{1,3}}\\.[0-9]{{1,3}})*)\""
#define DFREGEX_VERSIONVB "\"(\\d+\\.\\d+\\.\\d+)\""
#define DFREGEX_VERSIONNET "\"(\\d+\\.\\d+\\.\\d+\\.\\d+)*)\""
#define DFREGEX_SINGLELETTER "\"([(A-Z)|(a-z)])\""

#define DFREGEX_SPACER	"[[:space:]+]"


// definition for call
char* dfregex_getregexstring(char *regex_name, df_commandtype group);


char* dfregex_getregexstring(char *regex_name, df_commandtype group) {
	char *pattern;
	int id=0;
	
	// wait until we have a valid id
	while (id<=0) { id = sc_start(); usleep(500); }
	
	// catch common first
	if (strcmp(regex_name, "error") == 0) {
		pattern = DFREGEX_GENERALERROR;
	}
	
	// group for some speed benifit
	if (group == DF_ROW_COMMAND) {
		if (strcmp(regex_name, "rowrequest") == 0) {
			sc_add(id, "\\[ACK");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		if (strcmp(regex_name, "rowrequestroom") == 0) {
			sc_add(id, "\\[ACK");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetAdvancedStatus") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetTracksOtherInfo") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_TIME);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetArtists") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if ((strcmp(regex_name, "GetAlbums") == 0) || (strcmp(regex_name, "GetAlbumsForArtists") == 0) ||
					(strcmp(regex_name, "GetPlaylistsForSubGenre") == 0) || (strcmp(regex_name, "GetUserPlaylists") == 0)) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetAlbumDetails") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetCurrentPlayList") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_TIME);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if ((strcmp(regex_name, "GetTracksForPlaylist") == 0) || (strcmp(regex_name, "GetTracksAll") == 0) ||
					(strcmp(regex_name, "GetExtTracksByContributor") == 0)) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_TIME);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetRooms") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_BOOLEAN);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_BOOLEAN);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_BOOLEAN);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_BOOLEAN);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetSubGenresForGenre") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "GetGenres") == 0) {
			sc_add(id, "\\[Record");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_DATE);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
	}
	else {
		if (strcmp(regex_name, "void") == 0) {
			sc_add(id, DFREGEX_GENERALRESPONSE);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "findname") == 0) {
			sc_add(id, "\\[");
			sc_add(id, DFREGEX_STRINGUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_ANYTHING);
			sc_add(id, "\\]");
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "checkcoverimage") == 0) {
			sc_add(id, "CheckCoverImage");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getlibrarychecksum") == 0) {
			sc_add(id, "GetLibraryCheckSum");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getvolume") == 0) {
			sc_add(id, "GetVolume");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getplayerstatus") == 0) {
			sc_add(id, "GetPlayerStatus");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getshuffle") == 0) {
			sc_add(id, "GetShuffle");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_BOOLEAN);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getrepeat") == 0) {
			sc_add(id, "GetRepeat");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_BOOLEAN);
			pattern = sc_join(id);
		}
		/*
		else if (strcmp(regex_name, "gettrackname") == 0) {
			sc_add(id,"GetTrackName");
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_NUMBERUNQUOTED);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_STRINGOPTIONAL);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_STRINGREQUIRED);
			pattern = sc_join(id);
		}
		 */
		else if (strcmp(regex_name, "gettracknum") == 0) {
			sc_add(id, "GetTrackNum");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "gettrackposition") == 0) {
			sc_add(id, "GetTrackPosition");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_TIME);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getalbumartist") == 0) {
			sc_add(id, "GetAlbumArtist");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getdetailedtrackinfo") == 0) {
			sc_add(id, "GetDetailedTrackInfo");
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERUNQUOTED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_TIME);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id, DFREGEX_SPACER);
			sc_add(id, DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		} 
		else if (strcmp(regex_name, "gettrackname") == 0) {
			sc_add(id,"GetTrackName");
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_NUMBERUNQUOTED);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_STRINGOPTIONAL);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_NUMBERQUOTEDREQUIRED);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getplayingchecksum") == 0) {
			sc_add(id,"GetPlayingCheckSum");
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_NUMBERUNQUOTED);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		}
		else if (strcmp(regex_name, "getlastplayererror") == 0) {
			sc_add(id,"GetLastPlayerError");
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_NUMBERUNQUOTED);
			sc_add(id,DFREGEX_SPACER);
			sc_add(id,DFREGEX_STRINGOPTIONAL);
			pattern = sc_join(id);
		}
	}
	
	/*#ifdef DF_DEBUG
	dferrors_printdebug("rx: %s\n",pattern);
	#endif*/
	
	sc_clear(id);
	
	return pattern;
}
